IF OBJECT_ID('ssf.ptx_insert_task_dependency') IS NOT NULL
	DROP PROCEDURE ssf.ptx_insert_task_dependency
GO

CREATE PROCEDURE ssf.ptx_insert_task_dependency
	@task_id INT
	, @depends_on_task_id INT
	, @active_fl BIT = 1
	, @task_dependency_id INT = NULL OUTPUT
AS
/*
<object_header>

<object_summary>
	<purpose><![CDATA[

	]]></purpose>
</object_summary>

</object_header>
*/

SET NOCOUNT ON

-- ============
/*<code_comment><![CDATA[declare dynamic sql variables]]></code_comment>*/
DECLARE	@proc_error INT
			, @sql_error INT
			, @error_message NVARCHAR(2048)
			, @error_line INT
			, @row_count BIGINT
			, @nsql NVARCHAR(MAX)
			, @crlf CHAR(2) = CHAR(13) + CHAR(10)
			, @quote CHAR(1) = CHAR(39)
			, @tab CHAR(1) = CHAR(9)
-- ============

-- ============
/*<code_comment><![CDATA[check parameters]]></code_comment>*/
IF @task_id IS NULL
OR @depends_on_task_id IS NULL
OR @active_fl IS NULL
BEGIN
	RAISERROR('A required parameter is blank or null.', 16, 1)
	RETURN 1
END
-- ============

-- ============
/*<code_comment><![CDATA[insert task dependency]]></code_comment>*/
SET @task_dependency_id = NULL

INSERT ssf.ptx_task_dependency (
	task_id
	, depends_on_task_id
	, active_fl
)
VALUES (
	@task_id
	, @depends_on_task_id
	, @active_fl
)

SELECT @sql_error = @@ERROR
	, @row_count = @@ROWCOUNT
	, @task_dependency_id = SCOPE_IDENTITY()

IF @sql_error <> 0
BEGIN
	RAISERROR('The INSERT into the table <ssf.ptx_task_dependency> failed.', 16, 1)
	RETURN @sql_error
END
-- ============

RETURN @@ERROR
GO
